<?php
include("cIncludes.php");
$test = new iKernel;

			$url = new iUrl;
			$argv1 = $url->var_a;

			if($argv1 == "logout"){
            		header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'");
            		setcookie(COOKIE_PREFIX."user", "", time() - 7200, "/", "", "0");
            		setcookie(COOKIE_PREFIX."lastvisit", "", time() - 7200, "/", "", "0");
					
					$db = new DB("online");
					$db->delete("online_user='".USER_ID."'");

                  $test->redirect("/index.php");
			}

		if(isset($_POST['login'])){	
				$username = $_POST['login_email'];
	            $password = $_POST['login_password'];
	            $username = htmlentities($username);
	            $password = htmlentities($password);
	            $username = mysql_real_escape_string($username);
	            $password = mysql_real_escape_string($password);
	            $remember = $$_POST['remeber_me'];
				
				$db = new DB("users");
				$db->setColPrefix("user_");
				$db->select("user_email='$username'");
				
	            if($db->numRows() == 1){
	                $db->nextRecord();
	                    if(md5($password.$db->password_salt) == $db->password){
	              		    $cookie_value = $db->id.".".$db->password;
	             			$cookie_exp = isset($remember) ? time() + 3600 * 24 * 30 : time() + 3600 * 3;
	             			header("P3P: CP='NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM'");
	             			setcookie(COOKIE_PREFIX."user", $cookie_value, $cookie_exp, "/", "", "0");
	                       // $result = $this->dbquery("DELETE FROM ".DBPREFIX."online WHERE online_ip='".USER_IP."'");
	                       // $result = $this->dbquery("INSERT INTO ".DBPREFIX."online VALUES('".$data['user_id']."', '".USER_IP."', '".time()."', '".REQUEST_FILE."')");
	                       $test->redirect("/".$page);
	                       
	               }else{
	                    $this->content .= "<br /><strong style='color: red;'>Wrong username or password!</strong>";
	               }
	            }else{
	                    $this->content .= "<br /><strong  style='color: red;'>Wrong username or password!</strong>";
	            }
            }

?>